home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / kcl / akcl / akcl1615.lha / c / rel_ps2aix.c < prev    next >
C/C++ Source or Header  |  1989-05-19  |  3KB  |  93 lines

  1.  
  2. /* Copyright William Schelter. All rights reserved.  This file does
  3. the low level relocation which tends to be very system dependent.
  4. It is included by the file sfasl.c
  5. */
  6.  
  7. print_rel(rel,sym)
  8. struct syment *sym;
  9.  struct reloc *rel;
  10. {char tem[10];
  11.   printf(" (name = %s)",SYM_NAME(sym));
  12.  printf("{r_type=%d",rel->r_type);
  13.  fflush(stdout);
  14. }
  15.  
  16.  
  17. #ifdef DEBUG
  18.  
  19. #define describe_sym describe_sym1
  20. describe_sym1(n)
  21. int n;
  22. {char *str;
  23.  char tem[9];
  24.  struct syment *sym;
  25.  sym= &symbol_table[n];
  26.  str = SYM_NAME(sym);
  27.  if (debug == 0)  return 1;
  28.  printf ("sym-index = %d table entry at %x",n,&symbol_table[n]);
  29.  printf("symbol is (%s):\nsymbol_table[n]._n._n_name %d\nsymbol_table[n]._n._n_n._n_zeroes %d\nsymbol_table[n]._n._n_n._n_offset %d\nsymbol_table[n]._n._n_nptr[0] %d\nsymbol_table[n]._n._n_nptr[n] %d\nsymbol_table[n].n_value %d\nsymbol_table[n].n_scnum %d " 
  30. "\nsymbol_table[n].n_type %d\nsymbol_table[n].n_sclass %d\nsymbol_table[n].n_numaux %d", 
  31.     symbol_table[n]._n._n_name,
  32.     symbol_table[n]._n._n_n._n_zeroes ,
  33.     symbol_table[n]._n._n_n._n_offset ,
  34.     symbol_table[n]._n._n_nptr[0] ,
  35.     symbol_table[n]._n._n_nptr[1] ,
  36.     symbol_table[n].n_value ,
  37.     symbol_table[n].n_scnum ,
  38.     symbol_table[n].n_type ,
  39.     symbol_table[n].n_sclass ,
  40.     symbol_table[n].n_numaux );
  41. }
  42.  
  43. #endif 
  44.  
  45. #define LONG_AT_ADDR(p) LONG_AT_ADDR1(((unsigned char *)p))
  46. #define LONG_AT_ADDR1(p) (p[0] | (p[1] << 8) | (p[2] << 16) |(p[3] << 24))
  47. #define STORE_LONG(p,val) STORE_LONG1(((unsigned char *)p),val)
  48. #define STORE_LONG1(p,val) (p[3]=(val >> 24),p[0]=val,p[1]=(val >> 8),p[2]=(val >> 16))
  49.  
  50.  
  51.  
  52. relocate()
  53. {
  54.   char *where;
  55.   int old_val,new_val;
  56. #ifdef DEBUG
  57.   if (debug)
  58.     {print_rel(&relocation_info,&symbol_table[relocation_info.r_symndx]);
  59.      describe_sym(relocation_info.r_symndx);}
  60. #endif
  61.   where = the_start + relocation_info.r_vaddr;
  62.   dprintf (where has %x , *where);
  63.   dprintf(   at %x -->, where );
  64.   
  65.   if (relocation_info.r_type == R_ABS)
  66.     { dprintf( r_abs ,0);  return; }
  67.   old_val = LONG_AT_ADDR(where);
  68.   switch(relocation_info.r_type)
  69.     { int *q;
  70.     case R_DIR32:
  71.       new_val= old_val + symbol_table[relocation_info.r_symndx].n_value;
  72.       dprintf(new val r_dir32 %x , new_val);
  73.       STORE_LONG(where,new_val);
  74.       break;
  75.  
  76.     case R_PCRLONG:
  77.  
  78.       new_val = old_val - (int) start_address +
  79.     symbol_table[relocation_info.r_symndx].n_value;
  80.       dprintf( r_pcrlong new value = %x , new_val)
  81.       STORE_LONG(where,new_val);
  82.       break;
  83.  
  84.     default:
  85.       fprintf(stderr, "%d: unsupported relocation type.",
  86.           relocation_info.r_type);
  87.       FEerror("The relocation type was unknown",0,0);
  88.     }
  89.  
  90. }
  91.  
  92.  
  93.